package org.itstack.demo.netty.client;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.DatagramPacket;

import java.nio.charset.Charset;

public class MyClientHandler extends SimpleChannelInboundHandler<DatagramPacket> {

    // 接收服务端发来的消息
    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, DatagramPacket datagramPacket) throws Exception {
        String msg = datagramPacket.content().toString(Charset.forName("GBK"));
        System.out.println("UDP客户端接收到消息：" + msg);
    }
}
